// ts的数据类型
// number类型
let num: number = 123;
console.log(num);
let num1: number;
num1 = 456;
console.log(num1);

//  string类型
let str1: string = "12";
let str2: string = "23";
let str3: string;
// str3 = str1 + str2;
str3 = str1 + num1;

console.log(str1, str2, str3);//12  23  12456

// 布尔类型
let str4: string, num2: number, bool: boolean;
str4 = "124";
num2 = 55;
bool = true;
console.log(str4, num2, bool);

// bool = 123;  //会报错
console.log(bool);

// 字面量
let a: "liuchaochao";
a = "liuchaochao";

console.log(a);//liuchaochao
// 联合类型
let b: "123" | 456 | true;
b = "123";
b = 456;
b = true;
console.log(b);

// any 类型
let c: any;
c = 123;
let d: string;
d = c;
console.log(d, c);

// unknown 类型
let e: unknown;
e = false;
let f: string;
// f = e ;//会报错
console.log(e);

// void 类型
// function sum(a: number, b: number):
// number{
//     return a + b;
// }
// console.log(sum(1,2));

// function foo(a:number,b:string):
// string{
//     return a+b;
// }
// console.log(foo(1234,"bb"));


// function fun1(a:string,b:number):
// void{
//     let c:string = a+b;
//     console.log(c);
    
// }
// console.log(fun1("aa",2));

// 对象
let obj:{name:string,age:number};
obj={
    name:"liuchao",
    age:22
}
console.log(obj);

let obj2 : {name:string,age:number,sex?:string};
obj2 = {
    name:"liu",
    age:22,
    // sex:"nan"
}
console.log(obj2);

let obj3:{name:string,age:number,[propName:string]:unknown};
obj3={
    name:"sun",
    age:25,
    sex:"男",
    height:100
}
obj3.weight = 80 
console.log(obj3);


// array

let arr:string[];
arr = ["liu","wang","sun"];
console.log(arr);

let arr2 : number[];
arr2 = [1213,456,789];

let arr3 : boolean[];
arr3 = [true,false]
console.log(arr3);

// 第二种写法
let arr4 : Array<number>;
arr4 = [123,456,]
console.log(arr4);

let arr5 : Array<string>
arr5 = ["122","liui"]

let arr6:Array<boolean>
arr6 = [true,false]
console.log(arr5,arr6);

// 元组
let arr7:[string,number,boolean]
arr7=["liu",22,true]
console.log(arr7);


// 枚举enum
enum Color{
    Red,
    Yellow,
    Blue
}
let aa:Color = Color.Blue;
console.log(aa,Color.Red,Color.Yellow);
console.log(Color[0],Color[1],Color[2]);


// 手动指定枚举中的值
enum Color1{
    Yellow =5,
    Pink,
    Red
}
console.log(Color1[5],Color1.Red,Color1["Pink"]);

// 类型联合
let ab:"liu"|"wang"|"xiaoming"|1234;
ab = "liu";
aa=123
// 在函数形参中也可以使用类型联合
function bc(a:string|number,b:number){
    console.log(a,b);
}
bc(12,34)

// 类型断言
function liu(g:number | string | true){
    if((<string>g).length){
        console.log(1234);
        return g.toString().length;
    }else{
        console.log(766);
        return g.toString().length
    }

}
console.log(liu(true),);
// function wang(h:number|string|boolean){
//     if((h as string).length){
//         console.log("trrut");
//         return (<string>h).length;
//     }else{
//         console.log("hkg");
//         return (<string>h).length
        
//     }
// }
// console.log(wang(false));

// 类型推断
// 第一种：定义变量时，赋值了，推断为对应的类型
let abc : "tufew";
// 第二种：定义变量时，没有赋值，，推断为any类型
let bcd;





























